import { createRouter, createWebHashHistory } from "vue-router";

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    component: () => import("../views/Home.vue"),
    children: [
      {
        path: "/home",
        redirect: "/home/index",
      },
      {
        path: "/home/index",
        component: () => import("../views/Home/Index.vue"),
        meta: {
          titleValue: "巴乐兔租房—线上租房平台，免佣金！",
        },
      },
      {
        path: "wishlist",
        component: () => import("../views/Home/Wishlist.vue"),
        meta: {
          titleValue: "心愿单-巴乐兔租房！",
        },
      },
      {
        path: "news",
        component: () => import("../views/Home/News.vue"),
        meta: {
          titleValue: "个人消息-巴乐兔租房！",
        },
      },
      {
        path: "mine",
        component: () => import("../views/Home/Mine.vue"),
        meta: {
          titleValue: "我的-巴乐兔租房！",
        },
      },
    ],
  },
  {
    path: "/detail/:id",
    component: () => import("../views/Detail.vue"),
    meta: {
      titleValue: "巴乐兔租房-房源详情",
    },
  },
  {
    path: "/consult",
    component: () => import("../views/Consult.vue"),
  },
  {
    path: "/commute",
    component: () => import("../views/Commute.vue"),
    children: [
      {
        path: "transit",
        component: () => import("../views/Commute/Transit.vue"),
      },
      {
        path: "drive",
        component: () => import("../views/Commute/Drive.vue"),
      },
    ],
    meta: {
      titleValue: "巴乐兔租房-通勤找房",
    },
  },
  {
    path: "/map",
    component: () => import("../views/Map.vue"),
    children: [
      {
        path: "around",
        component: () => import("../views/Map/Around.vue"),
      },
      {
        path: "subway",
        component: () => import("../views/Map/Subway.vue"),
      },
    ],
    meta: {
      titleValue: "巴乐兔租房-地图找房",
    },
  },
  {
    path: "/cities",
    component: () => import("../views/Cities.vue"),
    meta: {
      titleValue: "巴兔兔租房-城市选择",
    },
  },
  {
    path: "/mall",
    component: () => import("../views/Mall.vue"),
    meta: {
      titleValue: "巴乐兔租房-积分商城",
    },
  },
  {
    path: "/signin",
    component: () => import("../views/Signin.vue"),
    meta: {
      titleValue: "巴乐兔租房-签到页面",
    },
  },
  {
    path: "/help",
    component: () => import("../views/Help.vue"),
    meta: {
      titleValue: "巴乐兔租房-帮我找房",
    },
  },
  {
    path: "/roommate",
    component: () => import("../views/Roommate.vue"),
  },
  {
    path: "/login",
    component: () => import("../views/Login.vue"),
    meta: {
      titleValue: "巴乐兔租房-登录页",
    },
  },
  {
    path: "/message",
    component: () => import("../views/Message.vue"),
    meta: {
      titleValue: "巴乐兔租房-系统消息",
    },
  },
  {
    path: "/brand",
    component: () => import("../views/Brand.vue"),
    meta: {
      titleValue: "巴乐兔租房-品牌公寓",
    },
  },
  {
    path: "/:pathMatch(.*)*",
    component: () => import("../views/NotFound404.vue"),
    meta: {
      titleValue: "NotFound 404",
    },
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

//全局后置钩子;
router.afterEach((to) => {
  document.title = to.meta.titleValue || "巴乐兔租房—线上租房平台，免佣金！";
});

export default router;
